import type { PageLoad } from './$types';
import { invoke } from '@tauri-apps/api/tauri';

export const load: PageLoad = async ({ url, route, params }) => {
    const { slug } = params;
    console.log("route=", route, " url=", url, " params=", params);

    try {
        // Call a Tauri command using @tauri-apps/api/tauri

        const response = await invoke('greet', { name: slug });

        console.log('Tauri command response:', response);

        return {
            post: {
                status: 200,
                title: `Title for ${params.slug} goes here`,
                content: `Response From Backend Rust: ${response}`,
            }
        };
    } catch (error) {
        console.error('Error calling Tauri command:', error);
        return {
            post: {
                status: 500,
                title: `Title for ${params.slug} goes here`,
                content: `Content for ${params.slug} goes here`,
            }
        };
    }

};